package org.jeecg.modules.paycenter.channel.pufa;

import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.paycenter.channel.bankdocking.dto.Acc;
import org.jeecg.modules.paycenter.enums.PayChannelEnum;
import org.jeecg.modules.paycenter.service.BaseMemberService;
import org.jeecg.modules.paycenter.service.IMemberChannelService;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.customer.entity.HyCustomerAccountBook;
import org.jeecg.modules.wlhy.hyconfig.entity.HyConfig;
import org.jeecg.modules.wlhy.hypfaccount.entity.HyPfAccount;
import org.jeecg.modules.wlhy.hypfaccount.service.IHyPfAccountService;
import org.jeecg.modules.wlhy.utils.HyConfigUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class PfMemberChannelService extends BaseMemberService implements IMemberChannelService {

    @Autowired
    private IHyPfAccountService hyPfAccountService;

    @Autowired
    private PfBankUtil pfBankUtil;

    //region base
    @Override
    public PayChannelEnum getChannelEnum() {
        return PayChannelEnum.PF;
    }

    @Override
    public String getChannel() {
        return PayChannelEnum.PF.channelType;
    }

    @Override
    public boolean checkChannel() {
        HyConfig config = HyConfigUtils.getConfig();
        return config.getPfIzUse();
    }
    //endregion

    //region 账户相关

    @Override
    public BigDecimal getAvailBal() {
        return null;
    }

    @Override
    public Result<?> getCustomerAvailBalStr(HyCustomer customer) {
        HyPfAccount customerAccountBook = hyPfAccountService.getCustomerAccount(customer.getId());
        if (customerAccountBook == null) {
            return Result.error("尚未开通钱包!");
        }
        //检查货主运费是否够支付
        BigDecimal availBal = pfBankUtil.getChildAccountBal(customerAccountBook.getChildAcctNo());
        if (availBal == null) {
            return Result.error("查询余额失败");
        }
        return Result.OK(availBal);
    }

    @Override
    public Result<?> getPlateformAvailBalStr() {
        return Result.error("暂不支持");
    }
    //endregion
}
